local ls = require("luasnip")
local s = ls.snippet
local i = ls.insert_node
local fmt = require("luasnip.extras.fmt").fmt

ls.add_snippets("rust", {
  s(
    "sqle",
    fmt(
      [[
pub async fn {}<'e, E>(
  executor: E,
  {}
) -> Result<(), sqlx::Error>
where
  E: sqlx::Executor<'e, Database = sqlx::MySql>,
{{
  {}
  Ok(())
}}
      ]],
      { i(1, "fn_name"), i(2, "fn_param"), i(0, "fn_body") }
    )
  ),
  s(
    "sqli",
    fmt(
      [[
pub async fn {}<'e, E>(
  executor: E,
  {}
) -> Result<(), sqlx::Error>
where
  E: sqlx::Executor<'e, Database = sqlx::MySql>,
{{
  let id = sqlx::query!("{}")
  .execute(executor)
  .await?
  .last_insert_id();
  Ok(())
}}
      ]],
      { i(1, "fn_name"), i(2, "fn_param"), i(0, "") }
    )
  ),
})
